import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:test01/okhttp_test/pojo/saveBasicFitnessInfo_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

import 'difficulty_page.dart';

/*
*
* 登录界面-------------健身目标选择
*
*
* */
class GoalsPage extends StatefulWidget {
  const GoalsPage({Key key}) : super(key: key);

  @override
  _GoalsPageState createState() => _GoalsPageState();
}

class _GoalsPageState extends State<GoalsPage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar:  AppBar(
          leading: GestureDetector(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(
              Icons.arrow_back_ios,
              size: 28,
              color: Colors.black,
            ),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
          automaticallyImplyLeading: true,
        ),
        body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(left: 41, top: 42.5),
                child: Text(
                  "你的目标是？",
                  style: TextStyle(
                      fontSize: 23, color: Color.fromRGBO(17, 17, 17, 1)),
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 41, top: 12),
                child: Text(
                  "我们将以此为你推荐训练计划，让你一试身手",
                  style: TextStyle(
                      fontSize: 14, color: Color.fromRGBO(51, 51, 51, 1)),
                ),
              ),
              GoalsList(),
            ]));
  }
}


class GoalsList extends StatefulWidget {
  const GoalsList({Key key}) : super(key: key);

  @override
  _GoalsListState createState() => _GoalsListState();
}

///类型选择
class _GoalsListState extends State<GoalsList> {
  //初始化数据
  List goals_list=["减脂","塑性","增肌","健康"];
  String goals_describe="体脂偏高，想快速减掉减掉赘肉，击退小肚腩";
  //数据被单击的下标
  int click_index;

  SaveBasicFitnessInfo _saveBasicFitnessInfo=SaveBasicFitnessInfo();

  void goalsClick(int clickindex){
    click_index=clickindex;
    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      margin: EdgeInsets.only(top: 12,left: 41),
      width: MediaQuery.of(context).size.width-82,
      height: 384,
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
              onTap: () async{
                goalsClick(index);
                print("界面跳转");
                _saveBasicFitnessInfo.target=click_index;
                bool xx=await saveBasicFitnessInfo(_saveBasicFitnessInfo,"/appuser/web/user/saveBasicFitnessInfo");
                if(xx){
                  Navigator.push(context, MaterialPageRoute(builder: (context) {
                    return DifficultyPage();
                  }));
                }
              },
              child:click_index==index?
              Container(
                color: Color.fromRGBO(204, 204, 204, 1).withOpacity(0.16),
                margin: EdgeInsets.only(top:12,bottom: 12),
                height: 78,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.only(left: 7,top: 12),
                      child: Text("${index+1}",style: TextStyle(fontSize: 29,color: Color.fromRGBO(17, 17, 17, 1)),),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 12,top: 12),
                      child:  Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            child: Text("${goals_list[index]}",style: TextStyle(fontSize: 21,color: Color.fromRGBO(17, 17, 17, 1))),
                          ),
                          Container(
                            width: MediaQuery.of(context).size.width-75.5-83.5,
                            child: Text("$goals_describe",style: TextStyle(
                              fontSize: 12,color: Color.fromRGBO(153, 153, 153, 1),
                            ),
                              overflow: TextOverflow.ellipsis,
                              maxLines: 1,

                            ),
                          ),
                        ],
                      ),
                    ),
                    Spacer(),
                    Container(
                      alignment: Alignment.center,
                      child: Icon(Icons.arrow_forward_ios_sharp,size: 12,color: Color.fromRGBO(204, 204, 204, 1),),
                    ),
                    SizedBox(width: 5,)
                  ],
                ),
              ):
              Container(
                margin: EdgeInsets.only(top:12,bottom: 12),
                height: 78,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.only(left: 7,top: 12),
                      child: Text("${index+1}",style: TextStyle(fontSize: 29,color: Color.fromRGBO(102, 102, 102, 1)),),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 12,top: 12),
                      child:  Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            child: Text("${goals_list[index]}",style: TextStyle(fontSize: 21,color: Color.fromRGBO(102, 102, 102, 1))),
                          ),
                          Container(
                            width: MediaQuery.of(context).size.width-75.5-83.5,
                            child: Text("$goals_describe",style: TextStyle(
                              fontSize: 12,color: Color.fromRGBO(153, 153, 153, 1),
                            ),
                              overflow: TextOverflow.ellipsis,
                              maxLines: 1,

                            ),
                          ),
                        ],
                      ),
                    ),
                    Spacer(),
                    Container(
                      alignment: Alignment.center,
                      child: Icon(Icons.arrow_forward_ios_sharp,size: 12,color: Color.fromRGBO(204, 204, 204, 1),),
                    ),
                    SizedBox(width: 5,)
                  ],
                ),
              ),
          );
        },
        itemCount: goals_list.length,
      ),
    );
  }
}



